package btanalyzer.db.report;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

public abstract class AbstractReport implements Report {
	
	protected static final String DELIMITER = "\n\n-------------------------------\n\n";
	
	private static final Logger log = LoggerFactory.getLogger(AbstractReport.class);
	
	@PersistenceContext
	protected EntityManager em;
	
	protected PrintWriter pw;
	
	@Override
	@Transactional
	public void generate() {
		try {
			pw = new PrintWriter(new File("reports/" + reportOutptFileName()));
		} catch (FileNotFoundException e) {
			log.error("error creating printWriter", e);
			throw new RuntimeException(e);
		}
		generateInt();
		pw.close();
		
	}

	protected abstract String reportOutptFileName();
	
	protected abstract void generateInt();
}
